package worktime.yft.demo.Controller;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import worktime.yft.demo.Entity.Project;
import worktime.yft.demo.Service.ProjectService;

@RestController
@CrossOrigin
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @RequestMapping("findProjects")
    public JSONArray findProjects(){
        return projectService.findProjects();
    }

    @RequestMapping("findProjectsName")
    public JSONObject findProjectsName(){
        JSONObject object = new JSONObject();
        object.put("projectsName",projectService.findAllProjectName());
        return object;
    }

    @RequestMapping("updateProject")
    public boolean updateProject(int id,String name,String note,boolean isover){
        return projectService.update(new Project(id,isover,name,note));
    }

    @RequestMapping("insertProject")
    public boolean insertProject(String name,String note){
        return projectService.insert(new Project(false,name,note));
    }
}
